<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>棋盘格</title>
    <style>
        svg {
            border: 1px solid;
            margin-top: 20px;
            display: block;
        }
    </style>
</head>

<body>
    <input type="text" placeholder="请输入">
    <input type='button' value="click">
    <svg width="500" height="500"></svg>

    <script>
        const svg = document.querySelector('svg');

        let str = '';
        let x = 0, y = 0;

        for (let row = 1; row <= 5; row++) { // 行
            if (row % 2 == 0) { // 偶数
                x = 50;
            } else { // 奇数
                x = 0;
            }
            for (let col = 1; col <= 5; col++) { // 列
                str += `<rect x=${x} y=${y} width="50" height="50" fill="black"/>`;
                x += 100;
            }
            y += 50;
            x = 0;
        }
        svg.innerHTML = str;


    </script>
</body>

</html>